/*
 * Copyright (C) 2010, Funcom AS, All Rights Reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @authors
 *  Svein Gunnar Larsen <sveingunnarlarsen@gmail.com>
 *  Erik Thune Lund <culex.eriklund@gmail.com>
 *  Michel Krohn-Dale <kronicz@gmail.com>
 */

package com.funcom.peeler.action;

import com.funcom.peeler.peelable.PeelComponent;

import java.awt.*;

public class Resize implements Change {

    PeelComponent component;

    int start_width, start_height, end_width, end_height;

    public Resize( PeelComponent component ) {
        this.component = component;
    }

    public Resize( PeelComponent component, Point old_size, Point new_size ) {
        if ( component == null || old_size == null || new_size == null ) throw new NullPointerException( "Resize must be created with valid parameters" );
        this.component = component;
        this.start_width = old_size.x;
        this.start_height = old_size.y;
        this.end_width = new_size.x;
        this.end_height = new_size.y;
    }

    public void doChange() {
        component.getComponent().setSize( end_width, end_height );

    }

    public void undoChange() {
        component.getComponent().setSize( start_width, start_height );
    }

    public void startChange() {
        start_width = component.getComponent().getWidth();
        start_height = component.getComponent().getHeight();
    }

    public void endChange() {
        end_width = component.getComponent().getWidth();
        end_height = component.getComponent().getHeight();
    }

    public boolean valid() {

        if ( ( start_width == end_width ) && ( start_height == end_height ) )
            return false;

        return true;
    }
}
